table of contents
PG_DUMPALL(1) | PostgreSQL 9.2.24 Documentation | PG_DUMPALL(1) |
NAME¶
pg_dumpall - extract a PostgreSQL database cluster into a script file
SYNOPSIS¶
pg_dumpall [connection-option...] [option...]
DESCRIPTION¶
pg_dumpall is a utility for writing out (“dumping”) all PostgreSQL databases of a cluster into one script file. The script file contains SQL commands that can be used as input to psql(1) to restore the databases. It does this by calling pg_dump(1) for each database in a cluster. pg_dumpall also dumps global objects that are common to all databases. (pg_dump does not save these objects.) This currently includes information about database users and groups, tablespaces, and properties such as access permissions that apply to databases as a whole.
Since pg_dumpall reads tables from all databases you will most likely have to connect as a database superuser in order to produce a complete dump. Also you will need superuser privileges to execute the saved script in order to be allowed to add users and groups, and to create databases.
The SQL script will be written to the standard output. Use the [-f|file] option or shell operators to redirect it into a file.
pg_dumpall needs to connect several times to the PostgreSQL server (once per database). If you use password authentication it will ask for a password each time. It is convenient to have a ~/.pgpass file in such cases. See Section 31.15, “The Password File”, in the documentation for more information.
OPTIONS¶
The following command-line options control the content and format of the output.
-a, --data-only
-c, --clean
-f filename, --file=filename
-g, --globals-only
-i, --ignore-version
-o, --oids
-O, --no-owner
-r, --roles-only
-s, --schema-only
-S username, --superuser=username
-t, --tablespaces-only
-v, --verbose
-V, --version
-x, --no-privileges, --no-acl
--binary-upgrade
--column-inserts, --attribute-inserts
--disable-dollar-quoting
--disable-triggers
Presently, the commands emitted for --disable-triggers must be done as superuser. So, you should also specify a superuser name with -S, or preferably be careful to start the resulting script as a superuser.
--inserts
--lock-wait-timeout=timeout
--no-security-labels
--no-tablespaces
--no-unlogged-table-data
--quote-all-identifiers
--use-set-session-authorization
-?, --help
The following command-line options control the database connection parameters.
-h host, --host=host
-l dbname, --database=dbname
-p port, --port=port
-U username, --username=username
-w, --no-password
-W, --password
This option is never essential, since pg_dumpall will automatically prompt for a password if the server demands password authentication. However, pg_dumpall will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.
Note that the password prompt will occur again for each database to be dumped. Usually, it's better to set up a ~/.pgpass file than to rely on manual password entry.
--role=rolename
ENVIRONMENT¶
PGHOST, PGOPTIONS, PGPORT, PGUSER
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 31.14, “Environment Variables”, in the documentation).
NOTES¶
Since pg_dumpall calls pg_dump internally, some diagnostic messages will refer to pg_dump.
Once restored, it is wise to run ANALYZE on each database so the optimizer has useful statistics. You can also run vacuumdb -a -z to analyze all databases.
pg_dumpall requires all needed tablespace directories to exist before the restore; otherwise, database creation will fail for databases in non-default locations.
EXAMPLES¶
To dump all databases:
$ pg_dumpall > db.out
To reload database(s) from this file, you can use:
$ psql -f db.out postgres
(It is not important to which database you connect here since the script file created by pg_dumpall will contain the appropriate commands to create and connect to the saved databases.)
SEE ALSO¶
Check pg_dump(1) for details on possible error conditions.
2017-11-06 | PostgreSQL 9.2.24 |